import Vue from "vue"
import App from "@/App.vue"
import Router from "vue-router"
// 引入路由
import router from "@/router"
import beforeEach from "@/router/before-each"
import afterEach from "@/router/after-each"
Vue.config.productionTip = false
//路由前置守卫
router.beforeEach(beforeEach)
//路由后置守卫
router.afterEach(afterEach)

// 修改路由跳转报错的bug-start
const originalPush = Router.prototype.push
Router.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject) { return originalPush.call(this, location, onResolve, onReject) }
  return originalPush.call(this, location).catch((err) => err)
}
// 修改路由跳转报错的bug--end

// EventBus总线
var EventBus = new Vue()
Object.defineProperties(Vue.prototype, {
  $bus: {
    get: function() {
      return EventBus
    }
  }
})

import store from "@/store"

// https://mp.weixin.qq.com/s/Cp5u5BXRhyPO0liQeGUcRQ
import "@/icons" //引入svg图标

import plugins from "./plugins" // plugins
Vue.use(plugins)

// https://www.npmjs.com/package/xiaobu-img-preview
import xiaobuImgPreview from "xiaobu-img-preview"
Vue.use(xiaobuImgPreview)

// https://www.npmjs.com/package/vue2-element-admin-plugin
import Vue2ElementAdminPlugin from "vue2-element-admin-plugin"
Vue.use(Vue2ElementAdminPlugin)

// 引入全局样式
import "@/styles/index.scss"

// 自动注册全局自定义指令
import "@/directives/index"

// 自动注册全局的过滤器
import "@/filters/index"

// 自动注册全局的组件
import "@/components/index"

import mixin from "@/mixin"
Vue.mixin(mixin)

// https://www.npmjs.com/package/vue2-water-marker
import vue2WaterMaker from "vue2-water-marker"
Vue.use(vue2WaterMaker)

// 引入获取验证码按钮 https://www.npmjs.com/package/vue-message-code
import vueMessageCode from "vue-message-code"
Vue.use(vueMessageCode)

//字典包配置文件 https://www.xiaobu.host/vue2-element-dict/
import dictSetting from "@/dict-setting.js"
import vue2ElementDict from "vue2-element-dict"
import { commonApi } from "./api"

commonApi.getSystemConfig().then(data => {
  if (data.systemName) {
    localStorage.setItem("systemName", data.systemName)
  }
  dictSetting.version = data.dictVersion
  //安装字典包
  Vue.use(vue2ElementDict, dictSetting)
  window.xiaobuAdminSystem = new Vue({
    store,
    router,
    render: h => h(App)
  }).$mount("#app")
})

